package com.xugui.learn.common.valid;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

import java.util.regex.Pattern;

/**
 * 手机号码校验器
 */
public class MobileValidator implements ConstraintValidator<Mobile, String> {

    private final Pattern pattern = Pattern.compile("^1[3-9]\\d{9}$");

    @Override
    public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
        if (value == null) return true;
        return pattern.matcher(value).matches();
    }
}
